// pages/profileInfo/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    originList: [],
    name: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log('----options', options)
    const { name } = options;
    this.setData({
      name
    })
    this.initAndUpdate(name);
  },
  initAndUpdate (name) {
    try {
      const healthInfo = wx.getStorageSync('healthInfo')
      console.log('healthInfo', healthInfo)
      const list = healthInfo[name];
      this.setData({
        list,
      })
    } catch (e) {
      // Do something when catch error
      console.log('0000e', e)
    }
  },
  handleDelete (data) {
    console.log('--data', data);
    const { time, names } = data.currentTarget.dataset;
    const healthInfo = wx.getStorageSync('healthInfo');
    const list = healthInfo[names] || [];
    const newList = [];
    list.forEach((item) => {
      if (item.time !== time) {
        newList.push(item)
      }
    })
    healthInfo[names] = newList;
    wx.setStorageSync('healthInfo', healthInfo);
    wx.showToast({
      title: '删除成功',
    })
    this.initAndUpdate(names);

  },
  hanldleBlur (e) {
    const { value } = e.detail;
    const originList = this.data.originList;
    const list = [];
    originList.forEach((item) => {
      if (item.name.includes(value)) {
        list.push(item)
      }
    })
    this.setData({
      list
    })
  },

  handleClick () {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})